﻿using QDP.Platform.Silverlight;
using System;
namespace Apps.Common
{
    [WidgetMeta(Key = WALL_STRING, Desc = "文字墙展现的文字列表，使用【WALL_SPLTOR】指定的符号分割。", DefaultValue = WALL_STRING_DEFAULT)]
    [WidgetMeta(Key = WALL_SPLTOR, Desc = "文字墙展现文字列表的分隔符，默认为逗号【,】。", DefaultValue = WALL_SPLTOR_DEFAULT)]
    [WidgetMeta(Key = WALL_WIDTH, Desc = "文字墙展现区域-宽度。", DefaultValue = WALL_WIDTH_DEFAULT)]
    [WidgetMeta(Key = WALL_HEIGHT, Desc = "文字墙展现区域-高度。", DefaultValue = WALL_HEIGHT_DEFAULT)]
    public class TextWallWidget : PartElement
    {
        public const string WALL_STRING = "WALL_STRING";
        public const string WALL_SPLTOR = "WALL_SPLTOR";
        public const string WALL_WIDTH = "WALL_WIDTH";
        public const string WALL_HEIGHT = "WALL_HEIGHT";
        public const string WALL_SPLTOR_DEFAULT = ",";
        public const int WALL_WIDTH_DEFAULT = 1440;
        public const int WALL_HEIGHT_DEFAULT = 900;

        public const string WALL_STRING_DEFAULT = "专题应用,GIS,管网专题,交通专题,旅游专题,环境专题,地理信息,Pipeline,Traffic,Environmental,Traveling,Smartting,Digital,智慧,Geographic Information System,Analysis,Remote Sensing,1101010,Destination";

        public TextWallWidget()
        {
            WidgetParent = Q.MainPage.Root;
        }

        public override void Show()
        {
            if (WidgetContent == null)
            {
                string splitorString = this.GetConfigValue(WALL_SPLTOR);
                if (string.IsNullOrEmpty(splitorString))
                    splitorString = WALL_SPLTOR_DEFAULT;
                string wallString = this.GetConfigValue(WALL_STRING);
                if (string.IsNullOrEmpty(wallString))
                wallString = WALL_STRING_DEFAULT.Replace(WALL_SPLTOR_DEFAULT, splitorString);
                int width = 0;
                if (Int32.TryParse(this.GetConfigValue(WALL_WIDTH), out width) == false)
                    width = WALL_WIDTH_DEFAULT;
                int height = 0;
                if (Int32.TryParse(this.GetConfigValue(WALL_HEIGHT), out height) == false)
                    height = WALL_HEIGHT_DEFAULT;

                WidgetContent = new TextWallControl()
                {
                    screen_height = height,
                    screen_width = width,
                    texts = wallString.Split(splitorString.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
                };
            }
            base.Show();
        }
    }
}